home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Startrek2.ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  12.4 KB  |  283 lines

  1. // GETINFO SCRIPTING
  2. // www.startrek.com episode import
  3.  
  4. (***************************************************
  5. *  Episode Information importation script for:     *
  6. *      http://www.startrek.Com                     *
  7. *                                                  *
  8. *  For use with Ant Movie Catalog 3.4.0            *
  9.  *  www.antp.be/software/moviecatalog              *
  10.  *                                                 *
  11.  *  This program is free software; you can         *
  12.  *  redistribute it and/or modify it under the     *
  13.  *  terms of the GNU General Public License as     *
  14.  *  published by the Free Software Foundation;     *
  15.  *  either version 2 of the License, or (at your   *
  16.  *  option) any later version.                     *
  17. *                                                  *
  18. ***************************************************)
  19.  
  20.  
  21. Program StarTrek;
  22. Var
  23.   IndexURL    : String;
  24.   EpisodeURL  : String;
  25.   Tmp         : String;
  26.  
  27. Function ShowSeries : Boolean;
  28. Begin
  29.   PickTreeClear;
  30.   PickTreeAdd('The Original Serie (TOS)', '');
  31.     PickTreeAdd('Season 1', 'http://www.startrek.com/startrek/view/series/TOS/episodes/index.html?season=1&category=production');
  32.     PickTreeAdd('Season 2', 'http://www.startrek.com/startrek/view/series/TOS/episodes/index.html?season=2&category=production');
  33.     PickTreeAdd('Season 3', 'http://www.startrek.com/startrek/view/series/TOS/episodes/index.html?season=3&category=production');
  34.   PickTreeAdd('The Next Generation (TNG)', '');
  35.     PickTreeAdd('Season 1', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=1&category=production');
  36.     PickTreeAdd('Season 2', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=2&category=production');
  37.     PickTreeAdd('Season 3', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=3&category=production');
  38.     PickTreeAdd('Season 4', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=4&category=production');
  39.     PickTreeAdd('Season 5', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=5&category=production');
  40.     PickTreeAdd('Season 6', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=6&category=production');
  41.     PickTreeAdd('Season 7', 'http://www.startrek.com/startrek/view/series/TNG/episodes/index.html?season=7&category=production');
  42.   PickTreeAdd('Deep Space Nine (DS9)', '');
  43.     PickTreeAdd('Season 1', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=1&category=production');
  44.     PickTreeAdd('Season 2', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=2&category=production');
  45.     PickTreeAdd('Season 3', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=3&category=production');
  46.     PickTreeAdd('Season 4', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=4&category=production');
  47.     PickTreeAdd('Season 5', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=5&category=production');
  48.     PickTreeAdd('Season 6', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=6&category=production');
  49.     PickTreeAdd('Season 7', 'http://www.startrek.com/startrek/view/series/DS9/episodes/index.html?season=7&category=production');
  50.   PickTreeAdd('Voyager (VOY)', '');
  51.     PickTreeAdd('Season 1', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=1&category=production');
  52.     PickTreeAdd('Season 2', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=2&category=production');
  53.     PickTreeAdd('Season 3', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=3&category=production');
  54.     PickTreeAdd('Season 4', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=4&category=production');
  55.     PickTreeAdd('Season 5', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=5&category=production');
  56.     PickTreeAdd('Season 6', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=6&category=production');
  57.     PickTreeAdd('Season 7', 'http://www.startrek.com/startrek/view/series/VOY/episodes/index.html?season=7&category=production');
  58.   PickTreeAdd('Enterprise (ENT)', '');
  59.     PickTreeAdd('Season 1', 'http://www.startrek.com/startrek/view/series/ENT/episodes/index.html?season=1&category=production');
  60.     PickTreeAdd('Season 2', 'http://www.startrek.com/startrek/view/series/ENT/episodes/index.html?season=2&category=production');
  61.     PickTreeAdd('Season 3', 'http://www.startrek.com/startrek/view/series/ENT/episodes/index.html?season=3&category=production');
  62.   ShowSeries := PickTreeExec(IndexURL);
  63. End;
  64.  
  65. Function CleanString(Str : String) : String;
  66. Begin
  67.   Str := StringReplace(Str, '<P>', #13#10);
  68.   HTMLDecode(Str);
  69.   HTMLRemoveTags(Str);
  70.   Str := Trim(Str);
  71.   Str := StringReplace(Str, #09, '');
  72.   If Pos(#13#10, Str) = 1 Then Begin
  73.     Str := Copy(Str, 3, Length(Str) - 2);
  74.   End;
  75.   CleanString := Str;
  76. End;
  77.  
  78. Function ShowEpisodes : Boolean;
  79. Var
  80.   Page      : TStringList;
  81.   I, J, K   : Integer;
  82.   Str       : String;
  83.   Tmp, Tmp1 : String;
  84.   Url       : String;
  85.   Title     : String;
  86.   EpisodeNo : String;
  87. Begin
  88.   PickTreeClear;
  89.   PickTreeAdd('Episodes', '');
  90.   Page := TStringList . Create;
  91.   Page . Text := GetPage(IndexURL);
  92.   I := 1;
  93.   While I < Page . Count Do Begin
  94.     Str := Page . GetString(I);
  95.     Tmp := '<td width="150" valign="top"><img src="images/spacer.gif" width="150" height="2"><br><a href="';
  96.     J := Pos(Tmp, Str);
  97.     If J > 0 Then Begin
  98.       K := J + Length(Tmp);
  99.       Tmp := Copy(Str, K, Length(Str) - K + 1);
  100.       K := Pos('"  alt="', Tmp);
  101.       If K > 0 Then Begin  (* URL *)
  102.         Url := Copy(Tmp, 1, K - 1);
  103.         Tmp1 := 'class="periwinkle">';
  104.         J := Pos(Tmp1, Tmp);
  105.         If J > 0 Then Begin (* Title *)
  106.           K := Pos('</a></td>', Tmp);
  107.           Title := Copy(Tmp, J + Length(Tmp1), K - (J + Length(Tmp1)));
  108.           HTMLDecode(Title);
  109.           I := I + 1; (* Episode Number *)
  110.           Str := Page . GetString(I);
  111.           J := Pos('<br>', Str);
  112.           If J > 0 Then Begin
  113.             K := Pos('</td>', Str);
  114.             EpisodeNo := Copy(Str, J + 4, K - (J + 4));
  115.             PickTreeAdd(EpisodeNo + ' - ' + Title, 'http://www.startrek.com' + Url); (* Add Episode to the tree *)
  116.           End;
  117.         End;
  118.       End;
  119.     End;
  120.     I := I + 1;
  121.   End;
  122.   ShowEpisodes := PickTreeExec(EpisodeURL);
  123. End;
  124.  
  125. Procedure ProcessEpisode;
  126. Var
  127.   Page      : TStringList;
  128.   PagePhoto : TStringList;
  129.   I, J, K   : Integer;
  130.   Str       : String;
  131.   Tmp, Tmp1 : String;
  132.   AirDate   : String;
  133.   StarDate  : String;
  134.   EpisodeNo : String;
  135.   Photo     : Boolean;
  136. Begin
  137.   SetField(fieldTranslatedTitle, GetField(fieldOriginalTitle));
  138.   Page := TStringList . Create;
  139.   Photo:= FALSE;
  140.   Page . Text := GetPage(EpisodeURL);
  141.   I := 1;
  142.   While I < Page . Count Do Begin
  143.     Str := Page . GetString(I);
  144.     (* Title *)
  145.     J := Pos('<span class="episodetitle">', Str);
  146.     If J > 0 Then Begin
  147.       Str := CleanString(Str);
  148.       SetField(fieldOriginalTitle, Str);
  149.     end else Begin
  150.       (* Air Date *)
  151.       J := Pos('<span class="mainwhite">Air Date:</span>', Str);
  152.       If J > 0 Then Begin
  153.         Tmp := Copy(Str, J + 47, 4);
  154.         SetField(fieldYear, Tmp);
  155.       end else Begin
  156.         (* Synopsis *)
  157.         J := Pos('<span class="headlinewhite">Synopsis</span>', Str);
  158.         If J > 0 Then Begin
  159.           I := I + 34;
  160.           Str := Page . GetString(I);
  161.           Str := CleanString(Str);
  162.           SetField(fieldDescription, Str);
  163.         End Else Begin
  164.           (* Cast = Actors *)
  165.           J := Pos('<span class="mainwhite">Cast:</span>', Str);
  166.           If J > 0 Then Begin
  167.             I := I + 4;
  168.             Tmp := Page . GetString(I);
  169.             Tmp1 := '';
  170.             While Length(Tmp) <> 0 Do Begin
  171.               Tmp := CleanString(Tmp);
  172.               I := I + 4;
  173.               Str := Page . GetString(I);
  174.               Str := CleanString(Str);
  175.               Tmp1 := Tmp1 + Tmp + ' as ' + Str + #13#10;
  176.               I := I + 4;
  177.               Tmp := Page . GetString(I);
  178.             End;
  179.             Tmp := GetField(fieldActors);
  180.             SetField(fieldActors, Tmp + Tmp1);
  181.           End Else Begin
  182.             (* Guest Cast = Actors *)
  183.             J := Pos('<span class="mainwhite">Guest Cast:</span>', Str);
  184.             If J > 0 Then Begin
  185.               I := I + 5;
  186.               Tmp := Page . GetString(I);
  187.               Tmp1 := '';
  188.               While Length(Tmp) <> 0 Do Begin
  189.               Tmp := CleanString(Tmp);
  190.                 I := I + 4;
  191.                 Str := Page . GetString(I);
  192.                 Str := CleanString(Str);
  193.                 Tmp1 := Tmp1 + Tmp + ' as ' + Str + #13#10;
  194.                 I := I + 4;
  195.                 Tmp := Page . GetString(I);
  196.               End;
  197.               Tmp := GetField(fieldActors);
  198.               SetField(fieldActors, Tmp + Tmp1);
  199.             End Else Begin
  200.               (* Creative Staff = Director + Comments *)
  201.               J := Pos('<span class="mainwhite">Creative Staff:</span>', Str);
  202.               If J > 0 Then Begin
  203.                 I := I + 2;
  204.                 Str := Page . GetString(I);
  205.                 While Str <> '</table>' Do Begin
  206.                   Tmp := CleanString(Str);
  207.                   If Tmp = 'Director:' Then Begin
  208.                     I := I + 2;
  209.                     Str := Page . GetString(I);
  210.                     Str := CleanString(Str);
  211.                     SetField(fieldDirector, Str);
  212.                   End Else If Tmp <> '' Then Begin
  213.                     Str := GetField(fieldComments);
  214.                     SetField(fieldComments, Str + Tmp + #13#10);
  215.                   End;
  216.                   I := I + 1;
  217.                   Str := Page . GetString(I);
  218.                 End;
  219.               End Else Begin
  220.                 (* Episode Number *)
  221.                 J := Pos('<span class="mainwhite">Episode No:</span>', Str);
  222.                 If J > 0 Then Begin
  223.                   Str := Copy(Str, J, Length(Str) - J);
  224.                   Str := CleanString(Str);
  225.                   Tmp := GetField(fieldComments);
  226.                   SetField(fieldComments, Tmp + Str + #13#10);
  227.                 End Else Begin
  228.                   (* Star Date *)
  229.                   J := Pos('<span class="mainwhite">Stardate:</span>', Str);
  230.                   If J > 0 Then Begin
  231.                     I := I + 2;
  232.                     Str := Page . GetString(I);
  233.                     Str := CleanString(Str);
  234.                     If Str <> '' Then Begin
  235.                       Tmp := GetField(fieldComments);
  236.                       SetField(fieldComments, Tmp + 'Stardate: ' + Str + #13#10);
  237.                     End;
  238.                   End Else Begin
  239.                     (* Picture *)
  240.                     Tmp := '<a class="periwinkle" HREF="javascript:openwindow(''/startrek/mediaview?';
  241.                     J := Pos(Tmp, Str);
  242.                     If (Photo = FALSE) And (J > 0) Then Begin
  243.                       K := Pos(''',''mediapopup', Str);
  244.                       Tmp := Copy(Str, J + Length(Tmp), K - (J + Length(Tmp)));
  245.                       PagePhoto := TStringList . Create;
  246.                       PagePhoto . Text := GetPage('http://www.startrek.com/startrek/mediaview?' + Tmp);
  247.                       Str := PagePhoto . GetString(26);
  248.                       J := Pos('/imageuploads/', Str);
  249.                       K := Pos('jpg', Str);
  250.                       Str := Copy(Str, J, K - J + 3);
  251.                       GetPicture('http://www.startrek.com/' + Str, FALSE);
  252.                       PagePhoto . Free;
  253.                       Photo := TRUE;
  254.                     End;
  255.                   End;
  256.                 End;
  257.               End;
  258.             End;
  259.           End;
  260.         End;
  261.       End;
  262.     End;
  263.     I := I + 1;
  264.   End;
  265.   SetField(fieldCountry, 'United States');
  266.   SetField(fieldProducer, 'Paramount Pictures');
  267.   SetField(fieldCategory, 'Star Trek');
  268.   Page . Free;
  269. end;
  270.  
  271. begin
  272.   If CheckVersion(3,4,0) Then Begin
  273.     If ShowSeries Then Begin
  274.       If ShowEpisodes Then Begin
  275.         ProcessEpisode;
  276.         DisplayResults;
  277.       End;
  278.     End;
  279.   End
  280.     Else
  281.       ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the                 version 3.4.0)');
  282. end.
  283.